/**
 * Created by 刘柘林 on 2016/12/10.
 */
function refresh(function_name){
    var post_data = {
        f_id : $("#fid li[data-selected='1']").val() || '0',
        s_id : $("#sid li[data-selected='1']").val() || '0',
        d_level : $("#d_lev li[data-selected='1']").val() || '0'
    };

    $.ajax({
        url : '/hospital/details',
        data : post_data,
        dataType : 'json',
        type : 'post',
        success : function_name
    })
};

function fid_click(res) {
    var s_html = "<li data-selected=\"1\" value= \"0\" class=\"select-cur\">全部</li>";
    $.each(res.dept_s, function(idx, obj) {
        s_html += "<li value="+obj.id+"\">"+obj.name+"</li>";
    });
    $("#sid ul").html(s_html);
    refresh_doc_list(res);
}

function refresh_doc_list(res) {
    var pre = document.getElementById("doctor_list");
    pre.parentNode.removeChild(pre);

    var newiframe = document.createElement('iframe'); //动态创建框架
    newiframe.id = "doctor_list";
    newiframe.scrolling="no";
    newiframe.width="95%";
    newiframe.height="500px";
    newiframe.src=res.doc_list_url;            //框架中加载的页面
    var dest =  document.getElementById("doctor_list_iframe");
    dest.appendChild(newiframe);
}

$(document).ready(function(){
    $("#fid").on('click','li',function(){
        refresh(fid_click);
    });
    $("#sid").on('click','li',function(){
        refresh(refresh_doc_list);
    });
    $("#d_lev").on('click','li',function(){
        refresh(refresh_doc_list);
    });
});

